package ustc.xiaoyang.karl.string;

/**
 * 541.反转字符串 II easy
 */
public class ReverseStringII541 {
    public static String reverseStr(String s, int k) {
        StringBuffer sb = new StringBuffer();
        int m = s.length();
        for (int i = 0; i < m; i += 2*k) {
            StringBuffer tmp = new StringBuffer();
            tmp.append(s.substring(i,Math.min(i+k,m)));
            tmp.reverse();
            sb.append(tmp);
            sb.append(s.substring(Math.min(i+k,m),Math.min(i+2*k,m)));
        }
        return sb.toString();
    }
}
